<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="description" content="" />
    <meta name="author" content="ChongMing" />
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="full-screen" content="yes">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-fullscreen" content="true">
    <meta name="360-fullscreen" content="true">
    <title>提交订单</title>
</head>
<link rel="stylesheet" href="../css/reset.css">
<link rel="stylesheet" href="../css/swiper-3.3.1.min.css">
<link rel="stylesheet" href="css/geneticTesting.css">
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../js/jquery.mobile-1.4.3.js"></script>
<script type="text/javascript" src="../js/swiper-3.3.1.jquery.min.js"></script>
<script type="text/javascript" src="js/geneticTesting.js"></script>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script src="js/ap.js"></script>
<script src="js/pingpp.js"></script>
<script type="text/javascript">
    $(function(){
        $('body').on('touchmove', function (event) {
            event.preventDefault();
        });
        if($.cookie("is_wechat")==1){
            $('.sub-order .order-detail .mode .right .wechat').hide();
            $('.sub-order .order-detail .mode .right .alipay .radio').hide();
            pay_type = 'alipay_wap';
        }else{
            pay_type = 'wx_pub';
        }
        $('.sub-order .order-detail .mode .right .wechat').click(function(){
            pay_type = 'wx_pub';
        });
        $('.sub-order .order-detail .mode .right .alipay').click(function(){
            pay_type = 'alipay_wap';
        });
        var address_id = geneticTesting.getQueryString('address_id');
        if(geneticTesting.getQueryString('id')){
            gene_id = geneticTesting.getQueryString('id');
        }else{
            gene_id = geneticTesting.getQueryString('gene_id');
        }
        var data = {
            uid:$.cookie("local_userId"),
            gene_id:gene_id,
            address_id:address_id
        }
        geneticTesting.ord_preview('address/getPrice',data)
        numberuid = /^[0-9]+.?[0-9]*$/;
        if(numberuid.test($.cookie("num"))){

            num = $.cookie('num');
            $('.sub-order .botpay .left .text .span_1').html('￥'+$.cookie('price')*num);
            $('.sub-order .botpay .left .text .span_2').html('(已省：￥'+num*$.cookie('sp')+')')
        }else{
            num = 1;

            $('.sub-order .order-detail .buy-num .right .num').html(num);
        }
        $('.sub-order .order-detail .buy-num .right .num').html(num);
        $('.sub-order .order-detail .buy-num .right .plus').click(function(){
            var price = $('#sub-order').data('price');
            var sp = $('body').attr('data-sp');
            num++
            $('.sub-order .order-detail .buy-num .right .num').html(num);
            $('.sub-order .botpay .left .text .span_1').html('￥'+price*num);
            $('.sub-order .botpay .left .text .span_2').html('(已省：￥'+num*sp+')')
        });
        $('.sub-order .order-detail .buy-num .right .reduce').click(function(){
            var price = $('#sub-order').data('price');
            var sp = $('body').attr('data-sp');
            if(num>1){
                num--
                $('.sub-order .order-detail .buy-num .right .num').html(num);
                $('.sub-order .botpay .left .text .span_1').html('￥'+price*num);
                $('.sub-order .botpay .left .text .span_2').html('(已省：￥'+num*sp+')')
            }else{
                num = 1
                $('.sub-order .order-detail .buy-num .right .num').html(num);
            }
        });
        code = geneticTesting.getQueryString("code");
        if(code){
            $.ajax({
                type: 'GET',
                url:  url + '/diagnosis/getcharge/',
                data: {         // 需要于客户端同步
                    uid: $.cookie("local_userId"),
                    order_id: geneticTesting.getQueryString("order_id"),
                    pay_method:"wx_pub",
                    code : code
                },
                dataType: 'jsonp',
                jsonp: 'callback',
                success: function (result) {
                    pingpp.createPayment(result.data.charge, function(result, err) {
                        if (result=="success") {
                            location.href = '../geneticTesting/orderdetail.html?id='+data.order_id;
                        } else {
                            console.log(result.data.msg)
                        }
                    });
                }
            });
        }

        //    点击支付
        $('.sub-order .botpay .right').click(function(){
            var address_id = $(this).data('address_id');
            var num = $('.sub-order .order-detail .buy-num .right .num').html();
            var price = $('#sub-order').data('price');
            var sp = $('body').attr('data-sp');
            $.cookie('num',num,{expirse:7,path:'/'});
            $.cookie('price',price,{expirse:7,path:'/'});
            $.cookie('sp',sp,{expirse:7,path:'/'});
            var data = {
                uid:$.cookie("local_userId"),
                gene_id:gene_id,
                address_id:address_id,
                num:num
            }
            geneticTesting.get('diagnosis/submitGeneDetectionOrder',data,function(res){
                if(res.ret==0){
                    console.log(res);
                    var data = res.data;
                    var odid = data.order_id
                    $.ajax({
                        type: 'GET',
                        url:  url + '/diagnosis/getcharge/',
                        data: {         // 需要于客户端同步
                            uid: $.cookie("local_userId"),
                            id:gene_id,
                            order_id: data.order_id,
                            pay_method:pay_type,
                            success_url : 'http://www.ekangjiuyi.net/EKang2.0/hospital_nurse/submitorder.html'
                        },
                        dataType: 'jsonp',
                        jsonp: 'callback',
                        success: function (result) {
                            if(pay_type == "alipay_wap"){
                                pingpp.createPayment(result.data.charge, function(result, err) {
                                    if (result=="success") {
                                        location.href = '../geneticTesting/orderdetail.html?id='+odid;
                                    }
                                });
                            }else{
                                var url = result.data.location_url;
                                location.href = url;
                            }
                        }
                    });
                }
                else{
                    console.log(res.msg);
                }
            });
        });
//        $('.sub-order .address-infor').click(function(){
//            location.href = '../editAdd.html'
//        });
    });
</script>
<body style=" background: #ebebeb; margin: auto;-webkit-overflow-scrolling: touch;overflow: scroll;">
<div class="sub-order" id="sub-order" data-price="{{total_amount}}">
    <div v-on:click="link2(address_id)" v-if="is_have_address==0" class="add-address">
        <img src="images/icon29.png">
        <p>还没收货地址<span>去添加</span></p>
    </div>
    <div v-on:click="link(address_id)" v-if="is_have_address==1" class="address-infor">
        <div class="name public"><p>收货人：</p><span>{{user_name}}</span></div>
        <div class="add public"><p>收货地址：</p><span>{{address_desc}}</span></div>
        <div class="phone public"><p>联系方式：</p><span>{{mobile}}</span></div>
    </div>
    <div class="order-detail">
        <div class="price">
            <div class="left">
                <img v-bind:src="gene_img_pic">
                <p>{{gene_name}}</p>
            </div>
            <div class="right">
                <p>￥{{total_amount}}元</p>
            </div>
        </div>
        <div class="buy-num">
            <p class="left">购买数量</p>
            <div class="right">
                <div class="plus public">+</div>
                <div class="num"></div>
                <div style=" line-height: 4.6vw" class="reduce public">-</div>
            </div>
        </div>
        <div class="mode">
            <p class="left">支付方式</p>
            <div class="right">
                <div class="wechat public">
                    <img class="icon" src="../hospital_nurse/images/icon42.png">
                    <img class="radio" src="../hospital_nurse/images/icon41.png">
                </div>
                <div class="alipay public">
                    <img class="icon" src="../hospital_nurse/images/icon43.png">
                    <img class="radio" src="../hospital_nurse/images/icon40.png">
                </div>
            </div>
        </div>
        <div class="remarks">
            <p class="left">备注：</p>
            <input type="text">
        </div>
    </div>
    <div class="botpay">
        <div class="left">
            <div class="text"><span class="span">合计：</span><span class="span_1">￥{{total_amount}}</span><span class="span_2">(已省：￥{{promotion_price}})</span></div>
        </div>
        <div class="right" data-address_id="{{address_id}}">支付</div>
    </div>
</div>
</body>
</html>